package com.ruoyi.app.controller;

import com.ruoyi.app.dto.ScanInsideDto;
import com.ruoyi.domain.ParkingInfo;
import com.ruoyi.dto.PaymentDto;
import com.ruoyi.app.dto.PaymentParkCardDto;
import com.ruoyi.app.service.IAppService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.dto.PaymentInsideDto;
import com.ruoyi.service.IParkingInfoService;
import com.ruoyi.wss.dahua.request.ScanInOutCodeRequest;
import com.ruoyi.wss.dahua.request.ScanOnSiteCodeRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * App端
 */
@Validated
@CrossOrigin
@RestController
@RequestMapping("/app")
public class AppController extends BaseController {

    @Autowired
    private IAppService appService;


    /**
     * 微信H5 - 通过code获取openid
     */
    @GetMapping("/getOpenidByCode")
    public AjaxResult getOpenidByCode(String code){
        return AjaxResult.success("", appService.getOpenidByCode(code));
    }

    /**
     * 微信小程序 - 通过code获取openid
     */
    @GetMapping("/getXcxOpenidByCode")
    public AjaxResult getXcxOpenidByCode(String code){
        return AjaxResult.success("", appService.getXcxOpenidByCode(code));
    }

    /**
     * 出入口扫码查询停车信息
     */
    @PostMapping("/scanInOutCode")
    public AjaxResult scanInOutCode(@RequestBody @Validated(ScanInOutCodeRequest.WxH5.class) ScanInOutCodeRequest scanInOutCodeRequest){
        return success(appService.scanInOutCode(scanInOutCodeRequest));
    }

    /**
     * 出入口扫码查询停车信息
     */
    @PostMapping("/v1/scanInOutCode")
    public AjaxResult scanInOutCodeV1(@RequestBody @Validated(ScanInOutCodeRequest.WxXcx.class) ScanInOutCodeRequest scanInOutCodeRequest){
        return success(appService.scanInOutCodeV1(scanInOutCodeRequest));
    }


    /**
     * 通过parkCode获取停车场信息
     */
    @GetMapping("/getParkingInfoByCode")
    public AjaxResult getParkingInfoByCode(String platformId, String parkCode){
        return success(appService.getParkingInfoByCode(platformId, parkCode));
    }

    /**
     * 停车缴费支付
     */
    @PostMapping("/payment")
    public AjaxResult payment(@RequestBody @Validated PaymentDto paymentDto){
        return success(appService.payment(paymentDto));
    }

    /**
     * 场内停车缴费支付
     */
    @PostMapping("/paymentInside")
    public AjaxResult paymentInside(@RequestBody @Validated PaymentInsideDto paymentInsideDto){
        return success(appService.paymentInside(paymentInsideDto));
    }

    /**
     * 停车缴费 有优惠券，0元支付
     */
    @PostMapping("/paymentDiscount")
    public AjaxResult paymentDiscount(@RequestBody @Validated PaymentDto paymentDto){
        return success(appService.paymentDiscount(paymentDto));
    }

    /**
     * 停车卡办理支付
     */
    @PostMapping("/paymentParkCard")
    public AjaxResult paymentParkCard(@RequestBody @Validated PaymentParkCardDto paymentParkCardDto){
        return success(appService.paymentParkCard(paymentParkCardDto));
    }

    /**
     * 场内扫码停车费用查询
     */
    @PostMapping("/scanOnSiteCode")
    public AjaxResult scanOnSiteCode(@RequestBody @Validated ScanInsideDto scanInsideDto){
        return success(appService.scanOnSiteCode(scanInsideDto));
    }

    /**
     * 获取停车场列表
     */
    @GetMapping("/getParkingSelect")
    public AjaxResult getParkingSelect(){
        return success(appService.getParkingSelect());
    }

    /**
     * 通过停车场和月份，计算停车卡价格
     */
    @GetMapping("/getParkCardAmount")
    public AjaxResult getParkCardAmount(Long parkId, Integer valid){
        return AjaxResult.success("", appService.getParkCardAmount(parkId, valid));
    }

    /**
     * 用于H5商户端，通过车牌号和优惠券Id查询 停车缴费信息
     */
    @GetMapping("/getParkingFee")
    public AjaxResult getParkingFee(@NotNull(message = "请选择需要发放的优惠券") Long couponId,
                                    @NotBlank(message = "请填写车牌号") String carNum){
        return AjaxResult.success("", appService.getParkingFee(couponId, carNum));
    }
}
